
import {
  queryPromotionPeople,
  queryPromotionPeopleList
} from "../../../../service/jb_promotion_service"
import {
  personSignMonthList
} from "../../../../service/jb_sign_service"
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuTop: app.globalData.menuButton.top,
    menuHeight: app.globalData.menuButton.height,
    requestData: {
      page: 1,
      limit: 10,
    },
    dataList: [


    ],
    isShowLoading: false,
    isBottomShow: false,
    refreshFlag: false,
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.querySignList('refresh');
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },





 
  querySignList(type) {
    wx.showLoading();
    personSignMonthList(this.data.requestData.page,this.data.requestData.limit).then(res => {
      wx.hideLoading();
      if (res.code == 200 && res.data) {
        let arr = (type == 'refresh' ? [] : this.data.dataList || []);
        arr = arr.concat(res.data.list || [])
        this.setData({
          dataList: arr,
          refreshFlag: false,
          isShowLoading: false,
          isBottomShow: res.data.totalPage == this.data.requestData.page ? true : false,
        })
       
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      if (this.data.requestData.page != 1) {
        this.setData({
          "requestData.page": this.data.requestData.page - 1
        })
      }
      this.setData({
        refreshFlag: false,
      })
      console.error('JJLog:querySignList', err);
    })
  },

  //下拉刷新
  handleRefresh() {
    // TODO
    this.setData({
      'requestData.page': 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.querySignList('refresh');
  },
  handleLoadmore() {
    console.log('加载更多');
    if (this.data.isBottomShow) {
      return;
    }
    this.setData({
      isShowLoading: true,
      "requestData.page": this.data.requestData.page + 1
    })
    this.querySignList()
  },


})